from accounts.models import *

def current_account(request):
	" Adds `account`: the current Account object, if available.  Otherwise None."
	return {'account':getattr(request, 'account', None)}
	
def current_account_user(request):
	" Adds `account_user`: the current AccountUser object, if available.  Otherwise None."
	account_user = None
	if request.user.is_authenticated() and getattr(request, 'account', None):
		try:
			account_user = AccountUser.objects.get(account=request.account, user=request.user)
		except AccountUser.DoesNotExist:
			pass
	return {'account_user': account_user}
	
def current_site(request):
	"Adds `site`: the current Site object, if available.  Otherwise None."
	return {'site': getattr(request, 'site', None) }
	
def account_info(request):
	"Convenient wrapper that adds `account`, `account_user` and `site` to the Context."
	d = {}
	d.update(current_account(request))
	d.update(current_account_user(request))
	d.update(current_site(request))
	return d